import type {
    ComponentInternalInstance,
    ComponentPublicInstance
} from "vue";

type Record<K extends keyof any, T> = {
    [P in K]: T;
};

type ProxyType<Refs = Record<string, unknown>> = {
    $refs: Refs;
} & ComponentPublicInstance


export default <Refs>(getCurrentInstance: () => ComponentInternalInstance | null) => {
    const { appContext, proxy: proxyOriginal } = getCurrentInstance() as ComponentInternalInstance
    const globalProperties = appContext.config.globalProperties
    const proxy = proxyOriginal as ProxyType<Refs>
    return {
        globalProperties,
        proxy
    }
}